package OptimalAlgorithm.SlidingWindow;

import java.util.HashSet;

//给定一个字符串 s ，请你找出其中不含有重复字符的 最长 子串 的长度。
//eg:
//输入: s = "pwwkew"
//输出: 3
public class LengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        char[] ch = s.toCharArray();
        int len = 0;
        HashSet<Character> set = new HashSet<>();
        int left = 0,right = 0;
        while (right < ch.length) {
            while (set.contains(ch[right])){
                set.remove(ch[left]);
                left++;
            }
            set.add(ch[right]);
            len = Math.max(len,right - left + 1);
            right++;
        }
        return len;
    }
}
